<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>清晰账本 - 交易详情</title>
    <link rel="stylesheet" href="glassmorphism.css">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }
        
        body {
            background: linear-gradient(45deg, #6a11cb, #2575fc);
            min-height: 100vh;
            color: #fff;
            padding-bottom: 80px;
        }
        
        .app-container {
            max-width: 480px;
            margin: 0 auto;
            padding: 20px;
        }
        
        .header {
            display: flex;
            align-items: center;
            margin-bottom: 30px;
            position: relative;
        }
        
        .back-button {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            position: absolute;
            left: 0;
            text-decoration: none;
            color: white;
        }
        
        .page-title {
            flex: 1;
            text-align: center;
            font-size: 20px;
            font-weight: bold;
        }
        
        .action-button {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            position: absolute;
            right: 0;
            cursor: pointer;
        }
        
        .transaction-amount {
            text-align: center;
            margin-bottom: 30px;
        }
        
        .amount-wrapper {
            font-size: 36px;
            font-weight: bold;
        }
        
        .amount-expense {
            color: #ff5e62;
        }
        
        .amount-income {
            color: #26de81;
        }
        
        .amount-label {
            font-size: 14px;
            opacity: 0.7;
            margin-top: 5px;
        }
        
        .detail-card {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 20px;
            padding: 25px;
            margin-bottom: 25px;
        }
        
        .detail-list {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }
        
        .detail-item {
            display: flex;
            align-items: flex-start;
        }
        
        .detail-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            flex-shrink: 0;
        }
        
        .detail-content {
            flex: 1;
        }
        
        .detail-label {
            font-size: 14px;
            opacity: 0.7;
            margin-bottom: 5px;
        }
        
        .detail-value {
            font-size: 16px;
        }
        
        .spacer {
            width: 100%;
            height: 1px;
            background: rgba(255, 255, 255, 0.1);
            margin: 5px 0;
        }
        
        .action-buttons {
            display: flex;
            gap: 15px;
            margin-top: 20px;
        }
        
        .action-btn {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 15px;
            padding: 15px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .action-btn:hover {
            background: rgba(255, 255, 255, 0.15);
        }
        
        .action-btn-icon {
            margin-bottom: 8px;
        }
        
        .action-btn-text {
            font-size: 14px;
        }
        
        .edit-btn {
            color: #26de81;
        }
        
        .delete-btn {
            color: #ff5e62;
        }
        
        .modal {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(5px);
            z-index: 1000;
            display: none;
            align-items: center;
            justify-content: center;
        }
        
        .modal-content {
            width: 90%;
            max-width: 320px;
            background: rgba(35, 35, 35, 0.95);
            backdrop-filter: blur(15px);
            border-radius: 15px;
            padding: 25px;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .modal-header {
            margin-bottom: 20px;
            text-align: center;
            font-size: 18px;
            font-weight: bold;
        }
        
        .modal-message {
            text-align: center;
            margin-bottom: 25px;
            opacity: 0.8;
        }
        
        .modal-actions {
            display: flex;
            justify-content: space-between;
        }
        
        .modal-button {
            flex: 1;
            padding: 12px;
            border-radius: 10px;
            text-align: center;
            cursor: pointer;
            font-size: 16px;
            margin: 0 5px;
        }
        
        .cancel-button {
            background: rgba(255, 255, 255, 0.1);
        }
        
        .delete-button {
            background: rgba(255, 94, 98, 0.2);
        }
        
        .toast {
            position: fixed;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(38, 222, 129, 0.2);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            padding: 15px 20px;
            color: white;
            font-size: 14px;
            opacity: 0;
            transition: opacity 0.3s;
            z-index: 1200;
        }
        
        .toast.show {
            opacity: 1;
        }
        
        .navigation {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            display: flex;
            justify-content: space-around;
            padding: 15px 0;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-top: 1px solid rgba(255, 255, 255, 0.2);
            z-index: 100;
        }
        
        .nav-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: rgba(255, 255, 255, 0.7);
            text-decoration: none;
            transition: color 0.3s;
        }
        
        .nav-item.active {
            color: #fff;
        }
    </style>
</head>
<body>
    <div class="app-container">
        <div class="header">
            <a href="javascript:history.back()" class="back-button">
                <i class="material-icons">arrow_back</i>
            </a>
            <div class="page-title">交易详情</div>
            <div class="action-button" onclick="toggleMenu()">
                <i class="material-icons">more_vert</i>
            </div>
        </div>
        
        <div class="transaction-amount">
            <div class="amount-wrapper" id="amountDisplay"></div>
            <div class="amount-label" id="typeLabel"></div>
        </div>
        
        <div class="detail-card">
            <div class="detail-list">
                <div class="detail-item">
                    <div class="detail-icon">
                        <i class="material-icons" id="categoryIcon"></i>
                    </div>
                    <div class="detail-content">
                        <div class="detail-label">分类</div>
                        <div class="detail-value" id="categoryName"></div>
                    </div>
                </div>
                
                <div class="detail-item">
                    <div class="detail-icon">
                        <i class="material-icons">event</i>
                    </div>
                    <div class="detail-content">
                        <div class="detail-label">日期</div>
                        <div class="detail-value" id="transactionDate"></div>
                    </div>
                </div>
                
                <div class="detail-item">
                    <div class="detail-icon">
                        <i class="material-icons">notes</i>
                    </div>
                    <div class="detail-content">
                        <div class="detail-label">备注</div>
                        <div class="detail-value" id="transactionNote">-</div>
                    </div>
                </div>
                
                <div class="spacer"></div>
                
                <div class="detail-item">
                    <div class="detail-icon">
                        <i class="material-icons">schedule</i>
                    </div>
                    <div class="detail-content">
                        <div class="detail-label">记录时间</div>
                        <div class="detail-value" id="recordTime"></div>
                    </div>
                </div>
            </div>
            
            <div class="action-buttons">
                <a href="#" class="action-btn edit-btn" id="editButton">
                    <div class="action-btn-icon">
                        <i class="material-icons">edit</i>
                    </div>
                    <div class="action-btn-text">编辑</div>
                </a>
                <div class="action-btn delete-btn" onclick="showDeleteModal()">
                    <div class="action-btn-icon">
                        <i class="material-icons">delete</i>
                    </div>
                    <div class="action-btn-text">删除</div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 删除确认模态框 -->
    <div class="modal" id="deleteModal">
        <div class="modal-content">
            <div class="modal-header">删除交易</div>
            <div class="modal-message">确定要删除这笔交易记录吗？此操作无法撤销。</div>
            <div class="modal-actions">
                <div class="modal-button cancel-button" onclick="closeDeleteModal()">取消</div>
                <div class="modal-button delete-button" onclick="confirmDelete()">删除</div>
            </div>
        </div>
    </div>
    
    <div class="toast" id="toast">操作成功</div>
    
    <div class="navigation">
        <a href="index.html" class="nav-item">
            <i class="material-icons">home</i>
            <span>首页</span>
        </a>
        <a href="transactions.html" class="nav-item active">
            <i class="material-icons">receipt_long</i>
            <span>交易</span>
        </a>
        <a href="statistics.html" class="nav-item">
            <i class="material-icons">pie_chart</i>
            <span>统计</span>
        </a>
        <a href="my_profile.html" class="nav-item">
            <i class="material-icons">person</i>
            <span>我的</span>
        </a>
    </div>
    
    <script src="app_data.js"></script>
    <script>
        // 全局变量
        let transactionId = null;
        let currentTransaction = null;
        
        // 初始化页面
        function initPage() {
            // 从URL获取交易ID
            const urlParams = new URLSearchParams(window.location.search);
            transactionId = urlParams.get('id');
            
            // 加载交易数据
            loadTransactionData();
        }
        
        // 加载交易数据
        function loadTransactionData() {
            if (!transactionId) {
                showToast('无效的交易ID', true);
                setTimeout(() => {
                    window.location.href = 'transactions.html';
                }, 2000);
                return;
            }
            
            const transactionManager = new window.AppData.TransactionManager();
            const transactions = transactionManager.getTransactions();
            
            currentTransaction = transactions.find(t => t.id === transactionId);
            
            if (!currentTransaction) {
                showToast('未找到交易记录', true);
                setTimeout(() => {
                    window.location.href = 'transactions.html';
                }, 2000);
                return;
            }
            
            displayTransactionDetails(currentTransaction);
        }
        
        // 显示交易详情
        function displayTransactionDetails(transaction) {
            // 设置交易金额和类型
            const amountDisplay = document.getElementById('amountDisplay');
            const typeLabel = document.getElementById('typeLabel');
            
            if (transaction.type === 'expense') {
                amountDisplay.innerHTML = `-${transaction.amount.toFixed(2)}`;
                amountDisplay.className = 'amount-wrapper amount-expense';
                typeLabel.textContent = '支出';
            } else {
                amountDisplay.innerHTML = `+${transaction.amount.toFixed(2)}`;
                amountDisplay.className = 'amount-wrapper amount-income';
                typeLabel.textContent = '收入';
            }
            
            // 设置分类信息
            const category = getCategoryById(transaction.categoryId, transaction.type);
            if (category) {
                document.getElementById('categoryIcon').textContent = category.icon;
                document.getElementById('categoryName').textContent = category.name;
            } else {
                document.getElementById('categoryIcon').textContent = 'help';
                document.getElementById('categoryName').textContent = '未知分类';
            }
            
            // 设置日期
            document.getElementById('transactionDate').textContent = formatDate(transaction.date);
            
            // 设置备注
            const noteElement = document.getElementById('transactionNote');
            if (transaction.note && transaction.note.trim() !== '') {
                noteElement.textContent = transaction.note;
            } else {
                noteElement.textContent = '无备注';
                noteElement.style.opacity = '0.5';
            }
            
            // 设置记录时间
            const recordTimeString = new Date(transaction.id.substr(0, 13) * 1).toLocaleString('zh-CN', {
                year: 'numeric',
                month: 'long',
                day: 'numeric',
                hour: '2-digit',
                minute: '2-digit'
            });
            document.getElementById('recordTime').textContent = recordTimeString;
            
            // 设置编辑链接
            document.getElementById('editButton').href = `add_transaction.html?edit=${transaction.id}`;
        }
        
        // 获取分类信息
        function getCategoryById(categoryId, type) {
            const categories = type === 'expense' ? window.AppData.expenseCategories : window.AppData.incomeCategories;
            return categories.find(category => category.id === categoryId);
        }
        
        // 格式化日期
        function formatDate(dateString) {
            const date = new Date(dateString);
            return date.toLocaleDateString('zh-CN', {
                year: 'numeric',
                month: 'long',
                day: 'numeric',
                weekday: 'long'
            });
        }
        
        // 显示删除确认模态框
        function showDeleteModal() {
            document.getElementById('deleteModal').style.display = 'flex';
        }
        
        // 关闭删除确认模态框
        function closeDeleteModal() {
            document.getElementById('deleteModal').style.display = 'none';
        }
        
        // 确认删除交易
        function confirmDelete() {
            if (!transactionId) return;
            
            const transactionManager = new window.AppData.TransactionManager();
            transactionManager.deleteTransaction(transactionId);
            
            // 显示删除成功提示
            showToast('交易已删除');
            
            // 关闭模态框
            closeDeleteModal();
            
            // 2秒后跳转回交易列表页
            setTimeout(() => {
                window.location.href = 'transactions.html';
            }, 2000);
        }
        
        // 显示提示
        function showToast(message, isError = false) {
            const toast = document.getElementById('toast');
            toast.textContent = message;
            toast.classList.add('show');
            
            if (isError) {
                toast.classList.add('error');
            } else {
                toast.classList.remove('error');
            }
            
            setTimeout(() => {
                toast.classList.remove('show');
            }, 3000);
        }
        
        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', initPage);
    </script>
</body>
</html> 